package com.jysz.certificate.persistence.model.system;

import java.util.List;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.apache.commons.lang.StringUtils;

import com.google.gson.annotations.Expose;
import com.jysz.certificate.persistence.model.cm.Certification;
import com.jysz.webcore.ssh.entity.AbstractBaseEntity;

@Entity
@Table(name = "sys_shop_")
@org.hibernate.annotations.Entity
public class Shop  extends AbstractBaseEntity<Long> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	@Expose
	private String shopName;//店名
	@Expose
	private String shopMark;//店号
	@Expose
	private String postcode;//邮编
	@Expose
	private String province;//省
	private String city;//市
	private Organization area;//区域
	private String company;//销售公司
	
	private Set<Brand> brands;//渠道
	private String address;//地址
	private Brand defaultBrand;//默认渠道
	private List<Treaty> childTreaty;
	private User user;// 创建人
	
	private Double moneyRoyaltyTiny;//绩效保底数
	private Double moneyRoyaltyAdding;//保底数递增
	private Double moneyStock;//本月在库
	private Double moneyRemain;//上月结存
	private Double moneyIndTiny;//金融机构独立开票保底数
	private Double moneyIndBig;//金融机构独立开票保底数递增
	
	@Column(name = "_money_royalty_tiny",columnDefinition="numeric(8,2)")
	public Double getMoneyRoyaltyTiny() {
		return moneyRoyaltyTiny;
	}
	public void setMoneyRoyaltyTiny(Double moneyRoyaltyTiny) {
		this.moneyRoyaltyTiny = moneyRoyaltyTiny;
	}
	@Column(name = "_money_royalty_adding",columnDefinition="numeric(8,2)")
	public Double getMoneyRoyaltyAdding() {
		return moneyRoyaltyAdding;
	}
	public void setMoneyRoyaltyAdding(Double moneyRoyaltyAdding) {
		this.moneyRoyaltyAdding = moneyRoyaltyAdding;
	}
	@Column(name = "_money_stock",columnDefinition="numeric(8,2)")
	public Double getMoneyStock() {
		return moneyStock;
	}
	public void setMoneyStock(Double moneyStock) {
		this.moneyStock = moneyStock;
	}
	@Column(name = "_money_remain",columnDefinition="numeric(8,2)")
	public Double getMoneyRemain() {
		return moneyRemain;
	}
	public void setMoneyRemain(Double moneyRemain) {
		this.moneyRemain = moneyRemain;
	}
	@Column(name = "_money_ind_tiny",columnDefinition="numeric(8,2)")
	public Double getMoneyIndTiny() {
		return moneyIndTiny;
	}
	public void setMoneyIndTiny(Double moneyIndTiny) {
		this.moneyIndTiny = moneyIndTiny;
	}
	@Column(name = "_money_ind_big",columnDefinition="numeric(8,2)")
	public Double getMoneyIndBig() {
		return moneyIndBig;
	}
	public void setMoneyIndBig(Double moneyIndBig) {
		this.moneyIndBig = moneyIndBig;
	}
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "_default_brand_id",columnDefinition="bigint(20)")
	public Brand getDefaultBrand() {
		return defaultBrand;
	}
	public void setDefaultBrand(Brand defaultBrand) {
		this.defaultBrand = defaultBrand;
	}

	
	@Expose(serialize =false,deserialize=false)
	private List<Certification> certification;
	@Expose(serialize =false,deserialize=false)
	private List<Treaty> treaties;
	private Integer toDelete;//是否删除
	
	@OneToMany(targetEntity = Treaty.class, cascade = { CascadeType.ALL }, mappedBy = "shop")  
	public List<Treaty> getTreaties() {
		return treaties;
	}
	
	public void setTreaties(List<Treaty> treaties) {
		this.treaties = treaties;
	}
	
	@OneToMany(targetEntity = Certification.class, cascade = { CascadeType.ALL }, mappedBy = "shop")  
	public List<Certification> getCertification() {
		return certification;
	}
	
	public void setCertification(List<Certification> certification) {
		this.certification = certification;
	}
	
	@Column(name = "_toDelete",columnDefinition="int(11)")
	public Integer getToDelete() {
		return toDelete;
	}
	
	public void setToDelete(Integer toDelete) {
		this.toDelete = toDelete;
	}

	@OneToMany(targetEntity = Treaty.class, cascade = { CascadeType.ALL }, mappedBy = "shop")  
	public List<Treaty> getChildTreaty() {
		return childTreaty;
	}
	
	public void setChildTreaty(List<Treaty> childTreaty) {
		this.childTreaty = childTreaty;
	}
	
	@Column(name = "_shuo_name",columnDefinition="varchar(100)")
	public String getShopName() {
		return shopName;
	}
	public void setShopName(String shopName) {
		this.shopName = shopName;
	}
	
	@Column(name = "_shop_mark", nullable = false, unique = true,columnDefinition="varchar(100)")
	public String getShopMark() {
		return shopMark;
	}
	
	public void setShopMark(String shopMark) {
		if(StringUtils.isNotBlank(shopMark)){
			shopMark = shopMark.toUpperCase();
			shopMark = shopMark.trim();
		}
			
		this.shopMark = shopMark;
	}
	
	@Column(name = "_postcode",columnDefinition="varchar(10)")
	public String getPostcode() {
		if(postcode != null){
			if(postcode.equals("null")){
				postcode = null;
			}
		}
		return postcode;
	}
	
	public void setPostcode(String postcode) {
		this.postcode = postcode;
	}
	
	@Column(name = "_province",columnDefinition="varchar(25)")
	public String getProvince() {
		return province;
	}
	
	public void setProvince(String province) {
		this.province = province;
	}
	
	@Column(name = "_city",columnDefinition="varchar(50)")
	public String getCity() {
		return city;
	}
	
	public void setCity(String city) {
		this.city = city;
	}
	@ManyToOne(fetch = FetchType.LAZY)  
	@JoinColumn(name = "_area",columnDefinition="bigint(20)")
	public Organization getArea() {
		return area;
	}
	
	public void setArea(Organization area) {
		this.area = area;
	}
	
	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "rs_sys_brand__sys_shop_", joinColumns = @JoinColumn(name = "_shop_id"), inverseJoinColumns = @JoinColumn(name = "_brand_id"))	
	public Set<Brand> getBrands() {
		return brands;
	}
	public void setBrands(Set<Brand> brand) {
		this.brands = brand;
	}
	@Column(name = "_address",columnDefinition="varchar(255)")
	public String getAddress() {
		
		return address;
	}
	@Column(name = "_company",columnDefinition="varchar(255)")
	public String getCompany() {
		if(company != null){
			if(company.equals("null")){
				company=null;
			}
		}
		
		return company;
	}
	
	public void setCompany(String company) {
		this.company = company;
	}
	
	public void setAddress(String address) {
		this.address = address;
	}
	
	@ManyToOne(fetch = FetchType.LAZY)  
	@JoinColumn(name = "_user_id",columnDefinition="bigint(20)") 
	public User getUser() {
		return user;
	}
	
	public void setUser(User user) {
		this.user = user;
	}


	/** property column names begin**/
		public static final String COLUMN_SHOP_NAME = "shopName";
		public static final String COLUMN_SHOP_MARK= "shopMark";
		public static final String COLUMN_PROVINCE = "province";
		public static final String COLUMN_CITY = "city";
		public static final String COLUMN_BRAND = "brands";
		public static final String COLUMN_TODELETE = "toDelete";
		public static final String COLUMN_AREA = "area";
		public static final String COLUMN_COMPANY = "company";
 
	/** property column names end**/

	 

}
